package cn.christ.com.mobilesafe.view.activity_sjfd;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.christ.com.mobilesafe.R;
import cn.christ.com.mobilesafe.common.Global;
import cn.christ.com.mobilesafe.common.utils.SPUtils;
import cn.christ.com.mobilesafe.constant.Constants;

/**
 * Created by Administrator on 2018/7/22.
 */

public class SetingUpActivity3 extends BaseSetingUpActivity {
    @BindView(R.id.tv_seting_title)
    TextView tvSetingTitle;
    @BindView(R.id.btn_select_phone)
    Button btnSelectPhone;
    @BindView(R.id.btn_next)
    Button btnNext;
    @BindView(R.id.btn_pre)
    Button btnPre;
    @BindView(R.id.et_safename)
    EditText etSafename;
    private String phone;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_setup3;
    }

    @Override
    public void initView() {
        phone = (String) SPUtils.get(Constants.SJFD_SAFE_NUM, "");
        if (!TextUtils.isEmpty(phone)) {
            etSafename.setText(phone);
            etSafename.setSelection(phone.length());
        }
    }

    @OnClick({R.id.btn_select_phone, R.id.btn_next, R.id.btn_pre})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_select_phone: //选择安全号
                Intent intent = new Intent(this, SelectContactsActivity.class);
                startActivityForResult(intent, Constants.SELECTCONTACTREQUESTCODE);
                break;
            case R.id.btn_next:
                phone = etSafename.getText().toString();
                if (TextUtils.isEmpty(phone)) {
                    Global.showToast(getString(R.string.safenum));
                    return;
                }
                performNext();
                finish();
                overridePendingTransition(R.anim.next_enter, R.anim.next_exit);
                break;
            case R.id.btn_pre:
                performPre();
                finish();
                overridePendingTransition(R.anim.pre_enter, R.anim.pre_exit);
                break;
        }
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @Override
    protected void next() {
        phone = etSafename.getText().toString();
        if (TextUtils.isEmpty(phone)) {
            Global.showToast(getString(R.string.safenum));
            return;
        }
        SPUtils.put(Constants.SJFD_SAFE_NUM, phone);
        performNext();
        finish();
        overridePendingTransition(R.anim.next_enter, R.anim.next_exit);
    }

    @Override
    protected void performPre() {
        startActivityNotFinish(SetingUpActivity2.class);
    }

    @Override
    protected void performNext() {
        startActivityNotFinish(SetingUpActivity4.class);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Constants.SELECTCONTACTREQUESTCODE) {
            if (resultCode == Constants.RESP_SELECT_CONTACT_CODE) {
                String phone = data.getStringExtra(Constants.PHONE);
                etSafename.setText(phone);
                etSafename.setSelection(phone.length());
            }
        }
    }

}
